/*
 *  Copyright (c) 2009-2010 jMonkeyEngine
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are
 *  met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 *  * Neither the name of 'jMonkeyEngine' nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
/*
 * Vector3fPropertyEditor.java
 *
 * Created on Apr 5, 2010, 1:11:20 AM
 */

package com.jme3.gde.cinematics.properties;

import com.jme3.math.Vector3f;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.beans.PropertyEditor;
import javax.swing.JLabel;
import javax.swing.JTextField;
import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;
import org.openide.util.NbBundle;

/**
 *
 * @author tomas
 */
public class Vector3fPropertyEditor extends javax.swing.JPanel implements PropertyEditor {

    /** Creates new form Vector3fPropertyEditor */
    public Vector3fPropertyEditor() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {







        xLabel = new JLabel();
        xText = new JTextField();
        yLabel = new JLabel();
        yText = new JTextField();
        zLabel = new JLabel();
        zText = new JTextField();

        xLabel.setText(NbBundle.getMessage(Vector3fPropertyEditor.class, "Vector3fPropertyEditor.xLabel.text_1")); // NOI18N
        xText.setText(NbBundle.getMessage(Vector3fPropertyEditor.class, "Vector3fPropertyEditor.xText.text_1")); // NOI18N
        yLabel.setText(NbBundle.getMessage(Vector3fPropertyEditor.class, "Vector3fPropertyEditor.yLabel.text_1")); // NOI18N
        yText.setText(NbBundle.getMessage(Vector3fPropertyEditor.class, "Vector3fPropertyEditor.yText.text_1")); // NOI18N
        zLabel.setText(NbBundle.getMessage(Vector3fPropertyEditor.class, "Vector3fPropertyEditor.zLabel.text_1")); // NOI18N
        zText.setText(NbBundle.getMessage(Vector3fPropertyEditor.class, "Vector3fPropertyEditor.zText.text_1")); // NOI18N
        GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(xLabel)
                        .addPreferredGap(LayoutStyle.RELATED)
                        .add(xText, GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(yLabel)
                        .addPreferredGap(LayoutStyle.RELATED)
                        .add(yText, GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(zLabel)
                        .addPreferredGap(LayoutStyle.RELATED)
                        .add(zText, GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(GroupLayout.BASELINE)
                    .add(xLabel)
                    .add(xText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(LayoutStyle.RELATED)
                .add(layout.createParallelGroup(GroupLayout.BASELINE)
                    .add(yLabel)
                    .add(yText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(LayoutStyle.RELATED)
                .add(layout.createParallelGroup(GroupLayout.BASELINE)
                    .add(zLabel)
                    .add(zText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private JLabel xLabel;
    private JTextField xText;
    private JLabel yLabel;
    private JTextField yText;
    private JLabel zLabel;
    private JTextField zText;
    // End of variables declaration//GEN-END:variables

    @Override
    public void setValue(Object value) {
        Vector3f val = (Vector3f) value;
        xText.setText("" + val.x);
        yText.setText("" + val.y);
        zText.setText("" + val.z);
    }

    @Override
    public Object getValue() {
        return new Vector3f(Float.parseFloat(xText.getText()), Float.parseFloat(yText.getText()), Float.parseFloat(zText.getText()));
    }

    @Override
    public boolean isPaintable() {
        return true;
    }

    @Override
    public void paintValue(Graphics gfx, Rectangle box) {
        //
    }

    @Override
    public String getJavaInitializationString() {
        return "Vector3f Editor Initialization";
    }

    @Override
    public String getAsText() {
        return getValue().toString();
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String[] getTags() {
        return new String[]{};
    }

    @Override
    public Component getCustomEditor() {
        return this;
    }

    @Override
    public boolean supportsCustomEditor() {
        return true;
    }

}
